package com.moji.controller.api;


import com.moji.common.base.ApiResult;
import com.moji.entity.MjSolution;
import com.moji.entity.vo.SelectUserVo;
import com.moji.entity.vo.SolutionVo;
import com.moji.service.MjSolutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 解决方案表(MjSolution)表控制层
 *
 * @author makejava
 * @since 2024-07-21 14:36:48
 */
@RestController
@RequestMapping("api/mjSolution")
@Api(tags = "解决方案列表相关api接口", value = "解决方案列表相关api接口")
public class MjSolutionController {
    /**
     * 服务对象
     */
    @Resource
    private MjSolutionService mjSolutionService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping
    @ApiOperation(value = "获取全部解决方案,不需要传参数")
    public  ApiResult<List<MjSolution>> queryByPage() {
        return ApiResult.ok(this.mjSolutionService.queryByPage());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/detail")
    @ApiOperation(value = "根据id查看解决方案",response = MjSolution.class)
    public ApiResult<MjSolution> queryById(@RequestParam("id") Long id) {
        return ApiResult.ok(this.mjSolutionService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param mjSolution 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "增加解决方案",response = MjSolution.class)
    public ApiResult<MjSolution> add(@Validated @RequestBody MjSolution mjSolution) {
        MjSolution mjSolution1=this.mjSolutionService.insert(mjSolution);
        if(mjSolution1==null)
       {
           return ApiResult.failed("此router已存在");
       }
        return ApiResult.ok(mjSolution1);
    }

    /**
     * 编辑数据
     *
     * @param mjSolution 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    @ApiOperation(value = "修改解决方案",response = MjSolution.class)
    public ApiResult<MjSolution> edit(@Validated @RequestBody MjSolution mjSolution) {
        if(this.mjSolutionService.update(mjSolution)==null)
        {
            return ApiResult.failed("此router已存在");
        }
        return ApiResult.ok(this.mjSolutionService.update(mjSolution));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除解决方案",response = Boolean.class)
    public ApiResult<Boolean> deleteById(@RequestParam("id")Long id) {
        return ApiResult.ok(this.mjSolutionService.deleteById(id));
    }

    @PostMapping("solutionSelect")
    @ApiOperation(value = "解决方案下拉框",response = SolutionVo.class)
    public ApiResult<List<SolutionVo>> solutionSelect() {
        return ApiResult.ok(mjSolutionService.solutionSelect());
    }
}

